<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Comments extends CI_Controller {
	
	function comments_insert(){

		if($this->session->userdata("user_id")){
			$para["user_id"]=$this->session->userdata("user_id");
			$para["comment"]=htmlspecialchars($_POST["comment"],ENT_COMPAT,UTF-8);
			$para["item_id"]=$_POST["item_id"];
			$para["creat_time"]= date('Y-m-d H:i:s');
			
			$this->db->insert('comments',$para);
				redirect('items/getItem/'.$_POST["item_id"]."/".$_POST["pastUrl"]);
			
		}else{
			$this->session->set_userdata("msg","please login");
			redirect('welcome');
		}
	}
	
	function comment(){
		$data["item_id"]=$this->uri->segment(3);
	
		if($this->session->userdata("user_id")){
			    $data['user_id']=$this->session->userdata("user_id");
		}else{
				$this->session->set_userdata('msg', "login first");
				redirect('items/mainShow/');
		}
		
		$this->load->view('comments/comment.php',$data);
	}
}
